<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 创建普通的html表单 -->
    <form action="" id="form">
        <input type="text" name="usename">

        <input type="password" name="password">
        <input type="button" value="提交112313" id="btn">
    </form>
    <script>
        //获取元素
        var btn = document.querySelector('#btn');
        var form = document.querySelector('#form')
            //添加点击事件
        btn.addEventListener('click', function() {
            //将普通的htnl表单转换为表单对象
            var formData = new FormData(form);
            //创建ajax对象
            var xhr = new XMLHttpRequest();
            //对ajax对象进行配置
            xhr.open('post', 'http://localhost:3000/formData');
            //发送ajax请求
            xhr.send(formData);
            //监听xhr对象下面的noload事件
            xhr.onload = function() {
                //对象http状态码进行判断
                if (xhr.status == 200) {
                    console.log(xhr.responseText);
                }
            }
        })
    </script>
</body>

</html>